﻿#ifndef WIDGET_H
#define WIDGET_H
#include <allstring.h>
#include <QWidget>
#include <QMap>
#include <libs/libdecryption.h>
#include <libs/libencryption.h>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QTableWidget>
#include <QPushButton>
#include <QTextBrowser>
#include <QProgressBar>
#include <threadpool.h>
#include <QTime>


class Widget : public QWidget
{
    Q_OBJECT


public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

signals:
    void freshStatus(QString fileName,QString status,bool finish);
    void flushUI();
    void setRunningStatus(bool ifRun);
    void errorMsg(const QString &msg);
    void showLog(const QString &msg);
    void setAllStatus(const QString &status);

private slots:
    void on_addFile_clicked();
    void on_showLog(const QString &msg);
    void on_errorMsg(const QString &msg);
    void on_flushUI();
    void resizeEvent(QResizeEvent *);
    void on_freshStatus(QString fileName, QString status, bool finish);
    void on_setRunningStatus(bool ifRun);
    void on_deleteFile_clicked();
    void on_clearList_clicked();
    void on_encrypt_clicked();
    void on_decrypt_clicked();
    void on_clearLog_clicked();
    void on_setAllStatus(const QString &status);

    void closeEvent(QCloseEvent *ev);

private:
    bool ifCanRun();

private:
    bool initOk;
    bool isRunning;
    QString outputDir;
    double password;
    QMap<QString,QString> fileList;
    int finishNum;
    ThreadPool pool;
    uint maxThreadNum;
    QTime oldTime;
private:
    QListWidget *log;
    QTableWidget *fileListWgt;
    QPushButton *addFile;
    QPushButton *deleteFile;
    QPushButton *encrypt;
    QPushButton *decrypt;
    QPushButton *clearList;
    QPushButton *clearLog;
    QTextBrowser *ad;
    QProgressBar *progress;
    QLabel *psLab;
    QLabel *psLab2;
    QLabel *prefixLab;
    QLineEdit *passwordWgt;
    QLineEdit *passwordWgt2;
    QLineEdit *prefixWgt;
    QLabel *maxThreadLab;
    QLineEdit *maxThreadWgt;
};


void encryptThread(QString outputDir, QString prefix, QString filePath, double password, Widget *wnd);
void decryptThread(QString outputDir,QString prefix,QString filePath,double password,Widget*wnd);
mwArray str2Mw(QString str,Widget* wnd);
mwArray num2Mw(double num,Widget* wnd);



#endif // WIDGET_H
